﻿using System;
using System.Diagnostics;
using Cmpp.Client.Cmpp3Message;
using Cmpp.Client.Console.Properties;

namespace Cmpp.Client.Console {
    internal class Program {
        private static void Main() {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new ConsoleTraceListener());

            RunCmppClient();

            System.Console.ReadLine();
        }

        private static void RunCmppClient() {
            var client = new Cmpp3Client();
            client.DeliverRequested += ((sender, e) => {
                Debug.WriteLine("DestinationId: " + e.Response.DestinationId);
                Debug.WriteLine("SourceTerminalId: " + e.Response.SourceTerminalId);
                Debug.WriteLine("CmppMessageFormat: " + e.Response.MessageFormat);
                Debug.WriteLine("MessageContent: " + e.Response.MessageContent);
            });

            client.Connect(Settings.Default.Server, Settings.Default.Port);
            var isLogin = client.Login(Settings.Default.SpId, Settings.Default.Password);

            if (isLogin) {
                System.Console.ReadLine();
                var submitRequest = new Cmpp3SubmitRequest {
                    AtTime = DateTime.Now,
                    DestinationType = TerminalType.Real,
                    FeeCode = "0",
                    FeeTerminalId = "15982821892",
                    FeeTerminalType = TerminalType.Real,
                    FeeType = FeeType.Free,
                    FeeUserType = FeeUserType.Source,
                    GSMProtocolId = 0,
                    LinkId = "",
                    MessageContent = "测试短信123ABC",
                    MessageFormat = CmppMessageFormat.GBK,
                    MessageId = ((uint)(new Random().Next())),
                    MessageLevel = 1,
                    MessageSource = "423007",
                    PacketNumber = 1,
                    PacketTotal = 1,
                    RequestDeliveryReport = false,
                    ServiceId = "423007",
                    SourceId = "10657024",
                    VaildTime = DateTime.Now.AddDays(2),
                    UserDataHreaderInfo = UserDataHreaderInfo.Normal
                };
                submitRequest.DestinationUsers.Add("13548003493");

                client.Submit(submitRequest);
                System.Console.ReadLine();

                client.Close();
            }
        }
    }
}